//
//  main.m
//  GCDBenchmarkCLI
//
//  Created by 郭晓龙 on 2025/11/26.
//

#import <Foundation/Foundation.h>
#include "auto_test.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Convert const char** to NSArray
        NSMutableArray *args = [NSMutableArray array];
        for (int i = 0; i < argc; i++) {
            [args addObject:[NSString stringWithUTF8String:argv[i]]];
        }

        // Check if --auto-test is present
        BOOL hasAutoTest = NO;
        for (NSString *arg in args) {
            if ([arg isEqualToString:@"--auto-test"]) {
                hasAutoTest = YES;
                break;
            }
        }

        if (hasAutoTest) {
            NSLog(@"[GCDBenchmarkCLI] Auto-test mode enabled");
            NSLog(@"[GCDBenchmarkCLI] Arguments: %@", args);

            // Call the shared test runner with our NSArray
            runAutoTestWithArguments(args);
        } else {
            NSLog(@"Usage: %@ --auto-test <test_name> [options]", [args firstObject]);
            NSLog(@"Example: %@ --auto-test fork_join --task-type 0 --task-count 512", [args firstObject]);
        }
    }
    return EXIT_SUCCESS;
}
